/**
 * 获取班级列表数据
 * 用于ajax动态加载班级信息
 */
public function classeslist()
{
    if ($this->request->isAjax() || $this->request->isGet()) {
        $apply_id = $this->request->param('apply_id', 0);
        $apply_type = $this->request->param('apply_type', 1);
        if (empty($apply_id)) {
            return json([
                'code' => 0,
                'msg' => 'apply_id参数不能为空',
                'data' => []
            ]);
        }
        
        try {
            // 根据apply_type选择JOIN的表
            $joinTable = 'classes c';
            if ($apply_type == 2) {
                $joinTable = 'OcationClass c';
            }
            
            // 查询课程表自动排课数据
            $list = Db::name('course_table_autoplan')
                ->alias('cta')
                ->field([
                    'cta.id',
                    'cta.classes_id',
                    'cta.ocation_id as location_id',
                    'cta.date',
                    'cta.start_time',
                    'cta.end_time',
                    'cta.table_type as course_type',
                    'cta.price fee',
                    'cta.num quota',
                    'cta.date class_time',
                    'cta.apply_form_id',
                    'cta.apply_type',
                    'cta.status',
                    'cta.create_time',
                    'cta.update_time'
                ])
                ->join($joinTable, 'cta.classes_id = c.id', 'LEFT')
                ->where('cta.apply_form_id', $apply_id)
                ->where('cta.bz', '从报名表班级导入生成')
                ->where('cta.status', '<>', -1)
                ->order('cta.create_time desc')
                ->select();
            
            $result = [];
            foreach ($list as $item) {
                // 构造上课时间字符串
                $class_time = '';
                if (!empty($item['date']) && !empty($item['start_time'])) {
                    $class_time = $item['date'] . ' ' . $item['start_time'];
                    if (!empty($item['end_time'])) {
                        $class_time .= '-' . $item['end_time'];
                    }
                }
                
                $result[] = [
                    'id' => $item['id'],
                    'class_id' => $item['classes_id'],
                    'location_id' => $item['location_id'],
                    'class_time' => $class_time,
                    'course_type' => $item['course_type'] ?: '1',
                    //'fee' => $item['fee'] ?: '',
                    //'quota' => $item['quota'] ?: '',
                    'apply_form_id' => $item['apply_form_id'],
                    'apply_type' => $item['apply_type'],
                    'status' => $item['status'],
                    'create_time' => $item['create_time'],
                    'update_time' => $item['update_time']
                ];
            }
            
            return json([
                'code' => 1,
                'msg' => '获取成功',
                'data' => $result,
                'count' => count($result)
            ]);
            
        } catch (\Exception $e) {
            return json([
                'code' => 0,
                'msg' => '获取班级数据失败：' . $e->getMessage(),
                'data' => []
            ]);
        }
    }
    
    return json([
        'code' => 0,
        'msg' => '请求方式错误',
        'data' => []
    ]);
}
